﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WF.Web.Pages.UserControl
{
    public partial class ToolBar : System.Web.UI.UserControl
    {
        public bool EnabledCustomer
        {
            get
            {
                if (null == this.ViewState["EnabledCustomer"])
                {
                    return false;
                }
                else
                {
                    return (bool)this.ViewState["EnabledCustomer"];
                }
            }
            set
            {
                this.ViewState["EnabledCustomer"] = value;
            }
        }

        public string OnClinetClickCustomer
        {
            get
            {
                if (null == this.ViewState["OnClinetClickCustomer"])
                {
                    return null;
                }
                else
                {
                    return (string)this.ViewState["OnClinetClickCustomer"];
                }
            }
            set
            {
                this.ViewState["OnClinetClickCustomer"] = value;
            }
        }

        public string CustomerText
        {
            get
            {
                if (null == this.ViewState["CustomerText"])
                {
                    return null;
                }
                else
                {
                    return (string)this.ViewState["CustomerText"];
                }
            }
            set
            {
                this.ViewState["CustomerText"] = value;
            }
        }

        public bool EnabledAdd
        {
            get
            {
                if (null == this.ViewState["EnabledAdd"])
                {
                    return false;
                }
                else
                {
                    return (bool)this.ViewState["EnabledAdd"];
                }
            }
            set
            {
                this.ViewState["EnabledAdd"] = value;
            }
        }

        public string OnClinetClickAdd
        {
            get
            {
                if (null == this.ViewState["OnClinetClickAdd"])
                {
                    return null;
                }
                else
                {
                    return (string)this.ViewState["OnClinetClickAdd"];
                }
            }
            set
            {
                this.ViewState["OnClinetClickAdd"] = value;
            }
        }

        public string CurrentDeptID
        {
            get
            {
                if (null == this.ViewState["CurrentDeptID"])
                {
                    return null;
                }
                else
                {
                    return (string)this.ViewState["CurrentDeptID"];
                }
            }
            set
            {
                this.ViewState["CurrentDeptID"] = value;
            }
        }

        public string CurrentEmpID
        {
            get
            {
                if (null == this.ViewState["CurrentEmpID"])
                {
                    return null;
                }
                else
                {
                    return (string)this.ViewState["CurrentEmpID"];
                }
            }
            set
            {
                this.ViewState["CurrentEmpID"] = value;
            }
        }

        public bool IsProtectAdd
        {
            get
            {
                if (null == this.ViewState["IsProtectAdd"])
                {
                    return false;
                }
                else
                {
                    return (bool)this.ViewState["IsProtectAdd"];
                }
            }
            set
            {
                this.ViewState["IsProtectAdd"] = value;
            }
        }

        public bool IsProtectCustomer
        {
            get
            {
                if (null == this.ViewState["IsProtectCustomer"])
                {
                    return false;
                }
                else
                {
                    return (bool)this.ViewState["IsProtectCustomer"];
                }
            }
            set
            {
                this.ViewState["IsProtectCustomer"] = value;
            }
        }

        public string AddOperateNo
        {
            get
            {
                if (null == this.ViewState["AddOperateNo"])
                {
                    return null;
                }
                else
                {
                    return (string)this.ViewState["AddOperateNo"];
                }
            }
            set
            {
                this.ViewState["AddOperateNo"] = value;
            }
        }


        public string CustomerOperateNo
        {
            get
            {
                if (null == this.ViewState["CustomerOperateNo"])
                {
                    return null;
                }
                else
                {
                    return (string)this.ViewState["CustomerOperateNo"];
                }
            }
            set
            {
                this.ViewState["CustomerOperateNo"] = value;
            }
        }

        public bool EnabledCopy
        {
            get
            {
                if (null == this.ViewState["EnabledCopy"])
                {
                    return false;
                }
                else
                {
                    return (bool)this.ViewState["EnabledCopy"];
                }
            }
            set
            {
                this.ViewState["EnabledCopy"] = value;
            }
        }

        public bool EnabledRefresh
        {
            get
            {
                if (null == this.ViewState["EnabledRefresh"])
                {
                    return false;
                }
                else
                {
                    return (bool)this.ViewState["EnabledRefresh"];
                }
            }
            set
            {
                this.ViewState["EnabledRefresh"] = value;
            }
        }

        public bool EnabledBack
        {
            get
            {
                if (null == this.ViewState["EnabledBack"])
                {
                    return false;
                }
                else
                {
                    return (bool)this.ViewState["EnabledBack"];
                }
            }
            set
            {
                this.ViewState["EnabledBack"] = value;
            }
        }

        public string OnClinetClickBack
        {
            get
            {
                if (null == this.ViewState["OnClinetClickBack"])
                {
                    return null;
                }
                else
                {
                    return (string)this.ViewState["OnClinetClickBack"];
                }
            }
            set
            {
                this.ViewState["OnClinetClickBack"] = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                btnCustomer.Visible = EnabledCustomer;
                btnCustomer.Attributes["onclick"] = OnClinetClickCustomer;
                this.ViewState["__ToolBar_OnClinetClickCustomer"] = OnClinetClickCustomer;

                lblCustomer.Visible = EnabledCustomer;
                lblCustomer.Text = CustomerText;

                if (IsProtectAdd)
                {
                    BusinessObject.SecurityManager sm = new BusinessObject.SecurityManager();
                    if (sm.IsOperateAuthoried(this.AddOperateNo, this.CurrentDeptID, this.CurrentEmpID) >= WF.Common.AuthDeptRange.本人)
                    {
                        btnAdd.Visible = true;
                        btnAdd.Attributes["onclick"] = OnClinetClickAdd;
                        this.ViewState["__ToolBar_OnClinetClickAdd"] = OnClinetClickAdd;
                    }
                    else
                    {
                        btnAdd.Visible = false;
                    }
                }
                else
                {
                    btnAdd.Visible = EnabledAdd;
                    btnAdd.Attributes["onclick"] = OnClinetClickAdd;
                    this.ViewState["__ToolBar_OnClinetClickAdd"] = OnClinetClickAdd;
                }

                if (IsProtectCustomer)
                {
                    BusinessObject.SecurityManager sm = new BusinessObject.SecurityManager();
                    if (sm.IsOperateAuthoried(this.CustomerOperateNo, this.CurrentDeptID, this.CurrentEmpID) >= WF.Common.AuthDeptRange.本人)
                    {
                        btnCustomer.Visible = true;
                        btnCustomer.Attributes["onclick"] = OnClinetClickCustomer;
                        this.ViewState["__ToolBar_OnClinetClickAdd"] = OnClinetClickCustomer;
                    }
                    else
                    {
                        btnCustomer.Visible = false;
                    }
                }
                else
                {
                    btnCustomer.Visible = EnabledCustomer;
                    btnCustomer.Attributes["onclick"] = OnClinetClickCustomer;
                    this.ViewState["__ToolBar_OnClinetClickAdd"] = OnClinetClickCustomer;
                }


                btnRefresh.Visible = EnabledRefresh;
                btnBack.Visible = EnabledBack;

                if (OnClinetClickBack == string.Empty)
                {
                    btnBack.Attributes["onclick"] = "history.back();";
                }
                else
                {
                    btnBack.Attributes["onclick"] = "document.location.href='" + OnClinetClickBack + "'";
                }

                this.ViewState["__ToolBar_OnClinetClickBack"] = btnBack.Attributes["onclick"];
            }
            else
            {
                if (null != this.ViewState["__ToolBar_OnClinetClickCustomer"])
                {
                    btnCustomer.Attributes["onclick"] = (string)this.ViewState["__ToolBar_OnClinetClickCustomer"];
                }

                if (null != this.ViewState["__ToolBar_OnClinetClickAdd"])
                {
                    btnAdd.Attributes["onclick"] = (string)this.ViewState["__ToolBar_OnClinetClickAdd"];
                }

                if (null != this.ViewState["__ToolBar_OnClinetClickBack"])
                {
                    btnBack.Attributes["onclick"] = (string)this.ViewState["__ToolBar_OnClinetClickBack"];
                }
            }
        }
    }
}